import axios, { AxiosResponse } from "axios";
const jsonp = require("jsonp");

interface Reponse {
	ret: number;
	msg: string;
}
export async function fetchComment(req: Object) {
	const base_url = "https://api.bilibili.com/x/v2/reply?jsonp=jsonp&type=1";
	const res = await axios.get(base_url, {
		params: {
			...req
		}
	});

	return res;
}

export async function jsonpComment(
	req: {
		id: number;
	},
	callback: (err: NodeJS.ErrnoException, data: any) => any
) {
	let base_url = "https://api.bilibili.com/x/v2/reply?jsonp=jsonp&type=1&pn=1";
	base_url = base_url.concat(`&oid=${req.id}`);
	jsonp(base_url, null, (err: NodeJS.ErrnoException, data: any) => {
		callback(err, data);
	});
}
